﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechnicalIndicators.DateBased;
using TechnicalIndicators.Points;
using Utils;

namespace TechnicalIndicatorsIntegrationTests
{
	[TestClass]
	public class TrixITs
	{
		[TestMethod]
		public void TestTrix()
		{
			DateTime startDate = DateTime.Parse("01/01/2012 09:00:00");

			ObservableCollection2<DatedSeriePoint> source = new ObservableCollection2<DatedSeriePoint>();

			Trix trix = new Trix();
			trix.Source = new ReadWriteLockedObservableCollection<DatedSeriePoint>(source, new TimeSpan(0, 0, 1));

			trix.Configure(5);
			trix.Start();

			source.Add(new DatedSeriePoint(startDate, 3));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(1), 4));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(2), 5));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(3), 4));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(4), 5));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(5), 6));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(6), 4));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(7), 4.5m));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(8), 8));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(9), 4));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(10), 10));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(11), 10));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(12), 10));
			Assert.IsNull(trix.LastValue);
			source.Add(new DatedSeriePoint(startDate.AddSeconds(13), 8));
			Assert.AreEqual(10.52m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(14), 9));
			Assert.AreEqual(8.29m, Math.Round(trix.LastValue.Y, 2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(15), 7));
			Assert.AreEqual(5.44m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(16), 7));
			Assert.AreEqual(3.11m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(17), 7));
			Assert.AreEqual(1.45m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(18), 6.8m));
			Assert.AreEqual(0.25m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(19), 8));
			Assert.AreEqual(0.07m, Math.Round(trix.LastValue.Y,2));
			source.Add(new DatedSeriePoint(startDate.AddSeconds(20), 7));
			Assert.AreEqual(-0.26m, Math.Round(trix.LastValue.Y,2));
		}
	}
}
